﻿
var selectdate = '';

$(function () {
    var $input_dhhm = $('#js_input_dhhm');
    $input_dhhm.on('input', function () {
        if ($input_dhhm.val().length > 11) {
            $input_dhhm.val($input_dhhm.val().slice(0, 11));
        }
    });

    $("#birthday").datetimePicker({
        title: '日期',
        years: range(2020, 2022),
        times: function () { return []; },
        parse: function (str) {
            return str.split("-");
        },
        onChange: function (picker, values, displayValues) {
            selectdate = values[0] + values[1] + values[2];
            //console.log(values);
        }
    });

    //检查是否有预定
    //GetOrder();
    //qr();
});

function getBaseInfo(id) {
    $.ajax({
        type: "GET",
        url: "http://" + B_Url + "/api/baseInfo",
        data: { info: 'orgid', ID: id},
        success: function (result) {
            $('#job').val(result.YaoDianMing);
            $('#ydaddr').val(result.YaoDianDiZhi);
        },
        error: function (e) { }
    });

}

//获取已经预定信息
function GetOrder() {
    var ShenFenZheng = $('#js_input_sfz').val();
    var telephone = $('#js_input_dhhm').val();
    if (ShenFenZheng == undefined || ShenFenZheng == null || ShenFenZheng == '') {
        $.alert("没有身份证信息！", "请输入");
        return;
    }
    if (telephone == undefined || telephone == null || telephone=='') {
        $.alert("没有电话信息！", "请输入");
        return;
    }

    if (!checkIdCard(ShenFenZheng)) {
        $.alert("身份证校验失败！", "信息不全", function () {
        });
        return;
    }


    $.showLoading();
    var tm = setTimeout(function () {
        $.hideLoading();
        $.alert("系统繁忙，请稍后再试！", "超时", function () { });
    }, 20000);

    $.ajax({
        type: "GET",
        url: "http://" + B_Url + "/api/yudingfind",
        //数据，json字符串
        data: { info: 'getorder', ShenFenZheng: ShenFenZheng, telephone: telephone, selectdate: selectdate},
        success: function (result) {
            $.hideLoading();
            clearTimeout(tm);
            if (result == undefined || result == null || result.YaoDianID == null || result.YuDingShu == null) {
                $("#qr").empty();
                $.alert("没有预定记录！", "未预定", function () {                
                    return;
                });
            } else {
                //var time = getCurrentDateTime(result.XiaoShuShijian);
                //$('#exp_Time').text('二维码过期时间：' + time + ' 23:59:59');
                $('#exp_Time').text('二维码过期时间：' + $("#birthday").val() + ' 23:59:59');
                
                //qr('http:////www.163.com');
                qr("http:////" + B_Url + '/Main/weixin/yuding_Customer_order.html?id=' + result.ID + '&selectdate=' + result.YuDingRiQi);
                getBaseInfo(result.YaoDianID);
            }
        },
        error: function (e) { }
    });

   
}


//
function qr(url) {
    const canvas = qrcanvas.qrcanvas({ data: url, size: 150, foreground: 'red', background: 'white' });
    $("#qr").empty().html(canvas2image(canvas));
}

function canvas2image(canvas) {
    var image = new Image();
    image.src = canvas.toDataURL("image/png");
    return image;
}

function getCurrentDateTime(datetime) {
    var now = new Date(datetime);
    var year = now.getFullYear(); //得到年份
    var month = now.getMonth();//得到月份
    var date = now.getDate();//得到日期
    var day = now.getDay();//得到周几
    var hour = now.getHours();//得到小时
    var minu = now.getMinutes();//得到分钟
    var sec = now.getSeconds();//得到秒
    month = month + 1;
    if (month < 10) month = "0" + month;
    if (date < 10) date = "0" + date;
    if (hour < 10) hour = "0" + hour;
    if (minu < 10) minu = "0" + minu;
    if (sec < 10) sec = "0" + sec;
    var time = "";
    time = year + "-" + month + "-" + date;
    return time;
}


